package cate.common.table.res.holy_pet.scene_spot;

import cate.common.table.ESheet;

import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 灵宠-征途景点 Sheet
 *
 * @author ShenSL
 * @since 2023/8/24 15:26
 */
public class HolyPetSceneSpotSheet extends ESheet<HolyPetSceneSpotRow> {
    @Override
    public String getSheetName() {
        return "征途景点";
    }

    /**
     * 根据场景ID和景点ID获取配置
     */
    public HolyPetSceneSpotRow getRow(int sceneId, int placeId) {
        return getList().stream().filter(row -> row.sceneId == sceneId && row.placeId == placeId)
                .findAny().orElse(null);
    }

    /**
     * 获取随机景点
     */
    public int getRandomPlace(int sceneId, int placeId) {
        int[] places = getList().stream().filter(row -> row.sceneId == sceneId && row.placeId != placeId)
                .mapToInt(row -> row.placeId)
                .toArray();
        if (places == null || places.length == 0) {
            return 0;
        }
        return places[new Random().nextInt(places.length)];
    }

    /**
     * 获取所有场景ID
     */
    public Set<Integer> getScenes() {
        return getList().stream().map(row -> row.sceneId)
                .collect(Collectors.toSet());
    }

    /**
     * 获取场景解锁条件-总好感等级
     */
    public int favorSumForScene(int sceneId) {
        return getList().stream().filter(row -> row.sceneId == sceneId)
                .mapToInt(row -> row.condition)
                .min().orElse(0);
    }
}
